﻿using SDATA;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SABI
{
    public partial class frm0001B : Form
    {
        public frm0001B()
        {
            InitializeComponent();
        }


        private void frm0001B_Load(object sender, EventArgs e)
        {

        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            (Application.OpenForms["frmHome"] as frmHOME).CloseTab(this);
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            FRM.AskBeforeSave = chkAskBeforeSave.Checked;
            FRM.Display = chkDisplay.Checked;
            FRM.WarnNegativeExport = chkWarnNegativeExport.Checked;
            FRM.MessageWhenSaveOK = chkMessageWhenSaveOK.Checked;
            FRM.RefreshData = chkRefreshData.Checked;
            FRM.MessageExWhenSale = chkMessageExWhenSale.Checked;
            FRM.Preview = chkPreview.Checked;
            FRM.ShowRecentValue = chkShowRecentValue.Checked;
            FRM.MessageImWhenPurchase = chkMessageImWhenPurchase.Checked;
            FRM.UpdateInventoryName = chkUpdateInventoryName.Checked;

            FRM.PNK = CboVoucherTypeIDPNK.Text;
            FRM.PXK = CboVoucherTypeIDPXK.Text;
            FRM.PT = CboVoucherTypeIDPT.Text;
            FRM.PC = CboVoucherTypeIDPC.Text;
            FRM.DT = CboVoucherTypeIDDT.Text;
            FRM.PTH = CboVoucherTypeIDPTH.Text;
            FRM.PTNH = CboVoucherTypeIDPTNH.Text;
            FRM.PCNH = CboVoucherTypeIDPCNH.Text;
            FRM.HDBH = CboVoucherTypeIDHDBH.Text;
            FRM.HDMH = CboVoucherTypeIDHDMH.Text;
            FRM.HBTL = CboVoucherTypeIDHBTL.Text;
            FRM.PNKwm = CboVoucherTypeIDPNKwm.Text;
            FRM.PXKwm = CboVoucherTypeIDPXKwm.Text;
            FRM.VCNB = CboVoucherTypeIDVCNB.Text;
            FRM.ReceivedDeliveryKIT = CboReceivedDeliveryKIT.Text;
            FRM.InventoryStock = CboInventoryStock.Text;
            FRM.InventoryBalance = CboInventoryBalance.Text;
            FRM.AssetChangeValue = CboAssetChangeValue.Text;
            FRM.PBH = CboPBH.Text;
            FRM.PBEquipment = CboPBEquipment.Text;

            FRM.SaveConfig();

            SDLL.DLL02.Info("Cập nhật dữ liệu thành công!");

        }

        private void frm0001B_Shown(object sender, EventArgs e)
        {
            loadDATA();
        }

        void loadDATA()
        {
            string sql = "";
            sql = "Select * From tb0027 Where Disabled  = 0 Order by VoucherTypeID";
            DataTable dtvc = FRM.GetDataTable(sql);
            foreach (Control ct in tabPage1.Controls)
                if (ct.GetType() == typeof(SCBX.MultiColumnComboBox))
                    ((SCBX.MultiColumnComboBox)ct).DataSource = dtvc;
            foreach (Control ct in tabPage2.Controls)
                if (ct.GetType() == typeof(SCBX.MultiColumnComboBox))
                    ((SCBX.MultiColumnComboBox)ct).DataSource = dtvc;
            foreach (Control ct in tabPage3.Controls)
                if (ct.GetType() == typeof(SCBX.MultiColumnComboBox))
                    ((SCBX.MultiColumnComboBox)ct).DataSource = dtvc;

            //load config

            chkAskBeforeSave.Checked = FRM.AskBeforeSave;
            chkDisplay.Checked = FRM.Display;
            chkWarnNegativeExport.Checked = FRM.WarnNegativeExport;
            chkMessageWhenSaveOK.Checked = FRM.MessageWhenSaveOK;
            chkRefreshData.Checked = FRM.RefreshData;
            chkMessageExWhenSale.Checked = FRM.MessageExWhenSale;
            chkPreview.Checked = FRM.Preview;
            chkShowRecentValue.Checked = FRM.ShowRecentValue;
            chkMessageImWhenPurchase.Checked = FRM.MessageImWhenPurchase;
            chkUpdateInventoryName.Checked = FRM.UpdateInventoryName;

            CboVoucherTypeIDPNK.SelectedValue = FRM.PNK;
            CboVoucherTypeIDPXK.SelectedValue = FRM.PXK;
            CboVoucherTypeIDPT.SelectedValue = FRM.PT;
            CboVoucherTypeIDPC.SelectedValue = FRM.PC;
            CboVoucherTypeIDDT.SelectedValue = FRM.DT;
            CboVoucherTypeIDPTH.SelectedValue = FRM.PTH;
            CboVoucherTypeIDPTNH.SelectedValue = FRM.PTNH;
            CboVoucherTypeIDPCNH.SelectedValue = FRM.PCNH;
            CboVoucherTypeIDHDBH.SelectedValue = FRM.HDBH;
            CboVoucherTypeIDHDMH.SelectedValue = FRM.HDMH;
            CboVoucherTypeIDHBTL.SelectedValue = FRM.HBTL;
            CboVoucherTypeIDPNKwm.SelectedValue = FRM.PNKwm;
            CboVoucherTypeIDPXKwm.SelectedValue = FRM.PXKwm;
            CboVoucherTypeIDVCNB.SelectedValue = FRM.VCNB;
            CboReceivedDeliveryKIT.SelectedValue = FRM.ReceivedDeliveryKIT;
            CboInventoryStock.SelectedValue = FRM.InventoryStock;
            CboInventoryBalance.SelectedValue = FRM.InventoryBalance;
            CboAssetChangeValue.SelectedValue = FRM.AssetChangeValue;
            CboPBH.SelectedValue = FRM.PBH;
            CboPBEquipment.SelectedValue = FRM.PBEquipment;

        }


    }
}
